package edu.washington.cs.workflow.analysis.guistructure.uievents;

import org.uispec4j.Trigger;

import edu.washington.cs.workflow.analysis.guistructure.uievents.UIEvent.WINDOW;
import edu.washington.cs.workflow.util.Utils;

public class UIEventOutcome {

	private Throwable e = null;
	private WINDOW win = WINDOW.NONE;
	private Trigger t = null;
	//will this 
	private boolean closeCurrentPanel = false;
	
	public boolean closeCurrentPanel() {
		return this.closeCurrentPanel;
	}
	
	public void currentPanelClosed(boolean close) {
		this.closeCurrentPanel = close;
	}
	
	public void setError(Throwable e) {
		Utils.checkNotNull(e);
		this.e = e;
	}
	
	public void setWindowStatus(WINDOW w) {
		Utils.checkNotNull(w);
		this.win = w;
	}
	
	public void setTrigger(Trigger t) {
		Utils.checkNotNull(t);
		this.t = t;
	}
	
	public boolean isSuccess() {
		return e == null;
	}
	
	public WINDOW getWindow() {
		return win;
	}
	
	public boolean hasNewWindow() {
		return !win.equals(WINDOW.NONE);
	}
	
	public boolean isModalWindow() {
		return win.equals(WINDOW.MODAL);
	}
	
	public boolean isNonModalWindow() {
		return win.equals(WINDOW.NONMODAL);
	}
	
	public Throwable getError() {
		return e;
	}
	
	public Trigger getTrigger() {
		return this.t;
	}
	
	public boolean hasTrigger() {
		return this.t != null;
	}
	
	@Override
	public String toString() {
		return "has exception: " + (this.getError() != null) + ",  pop new window: " + this.hasNewWindow()
		    + "(" + win +  ")"
		    + ",  close current window: " + this.closeCurrentPanel();
	}
}